package com.darrenchan.leetcode;

import java.util.HashMap;
import java.util.Map;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2019-12-25 22:00
 */
public class Q961 {
    public int repeatedNTimes(int[] A) {
        Map<Integer, Integer> map = new HashMap<>();
        int res = 0;
        for (int key : A) {
            if (map.containsKey(key)) {
                if(map.get(key) + 1 == A.length / 2){
                    res = key;
                    break;
                }
                map.put(key, map.get(key) + 1);
            } else {
                map.put(key, 1);
            }
        }
        return res;
    }
}
